package com.job.dao.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.job.dao.RecruitDao;
import com.job.mapper.HrMapper;
import com.job.mapper.PositionInfoMapper;
import com.job.mapper.PositionMapper;
import com.job.pojo.Position;
import com.job.pojo.PositionInfo;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class RecruitDaoImpl implements RecruitDao {

    @Resource
    private PositionMapper positionMapper;

    @Resource
    private HrMapper hrMapper;

    @Resource
    private PositionInfoMapper positionInfoMapper;

    @Override
    public boolean deletePosition(int positionId) {
        LambdaQueryWrapper<Position> positionWrapper = new LambdaQueryWrapper<>();
        positionWrapper.eq(Position::getPositionId,positionId);
        return positionMapper.delete(positionWrapper) < 1;
    }

    @Override
    public boolean deletePositionInfo(int positionId) {
        LambdaQueryWrapper<PositionInfo> positionInfoWrapper = new LambdaQueryWrapper<>();
        positionInfoWrapper.eq(PositionInfo::getPositionId,positionId);
        return positionInfoMapper.delete(positionInfoWrapper) < 1;
    }

    @Override
    public Position queryPosition(Integer positionId) {
        LambdaQueryWrapper<Position> positionWrapper = new LambdaQueryWrapper<>();
        positionWrapper.eq(Position::getPositionId,positionId);
        return positionMapper.selectOne(positionWrapper);
    }

    @Override
    public PositionInfo queryPositionInfo(Integer positionId) {
        LambdaQueryWrapper<PositionInfo> positionInfoWrapper = new LambdaQueryWrapper<>();
        positionInfoWrapper.eq(PositionInfo::getPositionId,positionId);
        return positionInfoMapper.selectOne(positionInfoWrapper);
    }

    @Override
    public List<Position> queryPositionByHrId(String hrId) {
        LambdaQueryWrapper<Position> positionWrapper = new LambdaQueryWrapper<>();
        positionWrapper.eq(Position::getHrId,hrId);
        return positionMapper.selectList(positionWrapper);
    }
}
